$(function(){
	
	var form = $("form");
	
	form.submit(function(){
		
		var userName = form[0].userName;
		var userPwd = form[0].userPwd;
		
		if(userName.value.trim()==""){
			weui.topTips('请填写手机号码');
			$(userName).trigger("focus");
			return false;
		}
		
		if(!/^\d{11}$/.test(userName.value)){
			weui.topTips('请填写正确的11位手机号码');
			$(userName).trigger("focus");
			return false;
		}
		
		
		if(userPwd.value.trim()==""){
			weui.topTips('请填写密码');
			$(userPwd).trigger("focus");
			return false;
		}
		
		if(!/^.{3,20}$/.test(userPwd.value)){
			weui.topTips('请填写3-20位的密码');
			$(userPwd).trigger("focus");
			return false;
		}
		
		
		var loading = weui.loading("登录中...");
		
		$.post(
			"user/login.do",
			form.serializeArray(),
			function(data){
				loading.hide();
				if(data.ok){
					localStorage.setItem("token",data.token);
					location.replace("main.html");
				}else{
					weui.topTips(data.message);
				}
			},"json"
		);
		
		
		
		return false;
	});
	
	
});
